package cn.haoxsf.app.common.constant.config;

import cn.haoxsf.app.common.util.ToolUtil;
import com.alibaba.fastjson.JSON;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: app
 * @description: 系统配置常量
 * @author: Ele qvbanfm@qq.com
 * @create: 2020-04-03 17:58
 **/
public class ConstantConfig {
    private static Map<String, Object> CONSTANT = new ConcurrentHashMap<>();

    /**
     * 设置常量
     */
    public static <T> void setConstant(String key, T v) {
        if (ToolUtil.isOneEmpty(key, v)) {
            return;
        } else {
            CONSTANT.put(key, v);
        }
    }

    /**
     * 设置常量
     */
    public static void setConstantAll(Map<String, Object> map) {
        if (ToolUtil.isOneEmpty(map)) {
            return;
        } else {
            CONSTANT.putAll(map);
        }
    }

    /**
     * 获取常量
     *
     * @param key
     */
    public  static Object  getConstant(String key) {
        if (ToolUtil.isNotEmpty(key)) {
            Object string = CONSTANT.get(key);
            if(ToolUtil.isNotEmpty(string)){
               return string;
            }
        }
        return null;
    }
}
